package com.cleaningcloud.cld.controller;

import java.util.List;
import java.util.Map;

import com.cleaningcloud.cld.domain.dto.CldWorkplanDetailsDto;
import com.cleaningcloud.cld.domain.dto.CldWorkplanDto;
import com.cleaningcloud.cld.domain.dto.CldWorkplanSubmitDto;
import com.cleaningcloud.cld.domain.vo.CldWorkplanDetailsVo;
import com.cleaningcloud.cld.domain.vo.CldWorkplanVo;
import com.cleaningcloud.cld.service.ICldWorkplanDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldWorkplan;
import com.cleaningcloud.cld.service.ICldWorkplanService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 工作计划Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/workplan")
public class CldWorkplanController extends BaseController
{
    @Autowired
    private ICldWorkplanService cldWorkplanService;

    @Autowired
    private ICldWorkplanDetailsService cldWorkplanDetailsService;

    /**
     * 查询工作计划列表
     */
//    @RequiresPermissions("cld:workplan:list")
    @GetMapping("/list")
    public TableDataInfo list(CldWorkplanDto cldWorkplan)
    {
        startPage();
        List<CldWorkplanVo> list = cldWorkplanService.selectCldWorkplanList(cldWorkplan);
        return getDataTable(list);
    }

    /**
     * 工作计划按项目分组统计
     */
//    @RequiresPermissions("cld:workplan:list")
    @GetMapping("/groupByProjectList")
    public TableDataInfo groupByProjectList(CldWorkplanDto cldWorkplan)
    {
        startPage();
        List<Map<String,Object>> list = cldWorkplanService.selectCldWorkplanGroupProjectList(cldWorkplan);
        return getDataTable(list);
    }


    /**
     * 查询工作计划列表
     */
    @GetMapping("/getWorkPlanDetailsList")
    public TableDataInfo getWorkPlanDetailsList(CldWorkplanDetailsDto cldWorkplanDetailsDto)
    {
        startPage();
        return getDataTable(cldWorkplanDetailsService.selectCldWorkplanDetailsList(cldWorkplanDetailsDto));
    }

    /**
     * 查询工作计划列表
     */
    @GetMapping("/getDetailsList")
    public AjaxResult getDetailsList(CldWorkplanDetailsDto cldWorkplanDetailsDto)
    {
        return success(cldWorkplanDetailsService.selectCldWorkplanDetailsList(cldWorkplanDetailsDto));
    }


    /**
     * 查询工作计划明细列表
     */
    @GetMapping("/selectWorkPlanDetailsList/{workPlanId}")
    public AjaxResult getWorkPlanDetailsList(@PathVariable Long workPlanId)
    {
        return success(cldWorkplanDetailsService.getWorkPlanDetailsList(workPlanId));
    }


    /**
     * 获取工作计划详细信息
     */
//    @RequiresPermissions("cld:workplan:query")
    @GetMapping(value = "/{workplanId}")
    public AjaxResult getInfo(@PathVariable("workplanId") Long workplanId)
    {
        return success(cldWorkplanService.selectCldWorkplanByWorkplanId(workplanId));
    }

    /**
     * 新增工作计划
     */
//    @RequiresPermissions("cld:workplan:add")
    @Log(title = "工作计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldWorkplanDto cldWorkplan)
    {
        return toAjax(cldWorkplanService.insertCldWorkplan(cldWorkplan));
    }

    /**
     * 修改工作计划
     */
//    @RequiresPermissions("cld:workplan:edit")
    @Log(title = "工作计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldWorkplanDto cldWorkplan)
    {
        return toAjax(cldWorkplanService.updateCldWorkplan(cldWorkplan));
    }


    /**
     * 修改工作计划
     */
//    @RequiresPermissions("cld:workplan:audit")
    @Log(title = "工作计划", businessType = BusinessType.UPDATE)
    @PutMapping("/detailsAudit")
    public AjaxResult detailsAudit(@RequestBody CldWorkplanSubmitDto cldWorkplanSubmitDto)
    {
        return toAjax(cldWorkplanService.auditCldWorkplanSubmit(cldWorkplanSubmitDto));
    }

    /**
     * 删除工作计划
     */
//    @RequiresPermissions("cld:workplan:remove")
    @Log(title = "工作计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workplanIds}")
    public AjaxResult remove(@PathVariable Long[] workplanIds)
    {
        return toAjax(cldWorkplanService.deleteCldWorkplanByWorkplanIds(workplanIds));
    }
}
